<template>
    <div style="width: 100%">
        <p v-if="!noBtn">
            <el-button size="small" :disabled="disabled" type="primary"
                       @click="$refs['gdcd'].open(selection)">选择已有的
            </el-button>
            <el-button size="small" :disabled="disabled" type="danger"
                       @click="removeItem(item,'object')">
                清空
            </el-button>
        </p>
        <div class="config">
            <el-col :span="2">大版本：</el-col>
            <el-col :span="8">
                <span>前缀</span>
                <el-input :disabled="true" size="small" v-model="formData.majorPrefix"></el-input>
            </el-col>
            <el-col :span="6">
                <span class="l4">自增初值</span>
                <el-select :disabled="true" size="small" v-model="formData.majorIdentityProperty">
                    <el-option :value="1" label="字母序列"></el-option>
                    <el-option :value="2" label="数字序列"></el-option>
                </el-select>
            </el-col>
            <el-col :span="8">
                <span>后缀</span>
                <el-input :disabled="true" size="small" v-model="formData.majorSuffix"></el-input>
            </el-col>

            <el-col :span="2">分隔符：</el-col>
            <el-col :span="22">
                <el-select :disabled="true" size="small" v-model="formData.separatorRule">
                    <el-option value="_" label="_"></el-option>
                    <el-option value="-" label="-"></el-option>
                </el-select>
            </el-col>

            <el-col :span="2">小版本：</el-col>
            <el-col :span="8">
                <span>前缀</span>
                <el-input :disabled="true" size="small" v-model="formData.minorPrefix"></el-input>
            </el-col>
            <el-col :span="6">
                <span class="l4">自增初值</span>
                <el-select :disabled="true" size="small"
                           v-model="formData.minorIdentityProperty">
                    <el-option :value="1" label="字母序列"></el-option>
                    <el-option :value="2" label="数字序列"></el-option>
                </el-select>
            </el-col>
            <el-col :span="8">
                <span>后缀</span>
                <el-input :disabled="true" size="small" v-model="formData.minorSuffix"></el-input>
            </el-col>
        </div>
        <get-data-common-dialog title="选择已有版本规则"
                                ref="gdcd"
                                url="/api/manager-api/mx-version-rule/workingList"
                                :limit="1"
                                :isPage="true"
                                :column="column"
                                :source-data="selection"
                                @addToList="addToList">
        </get-data-common-dialog>
    </div>
</template>
<script>
import GetDataCommonDialog from "@/views/DMDComponent/getDataCommonDialog.vue";
import index from "../index"
import * as api from "@/api/modulManage/entity";

export default {
    name: "versionRules",
    components: {GetDataCommonDialog},
    mixins: [index],
    inject: ["temp"],
    data() {
        return {
            selection: [],
            formData: {
                separatorRule: "",

                majorPrefix: "",
                majorSuffix: "",
                majorIdentityProperty: "",

                minorPrefix: "",
                minorSuffix: "",
                minorIdentityProperty: "",
            },
            form: {
                separatorRule: "",

                majorPrefix: "",
                majorSuffix: "",
                majorIdentityProperty: "",

                minorPrefix: "",
                minorSuffix: "",
                minorIdentityProperty: "",
            },
            column: [
                {
                    label: "中文名称",
                    prop: "nameCn",
                    overHidden: true,
                },
                {
                    label: '英文名称',
                    prop: 'nameEn',
                    overHidden: true,
                },
                {
                    label: '编码标识',
                    prop: 'name',
                    overHidden: true,
                },
                {
                    label: "状态",
                    prop: "state",
                    type: "radio",
                    overHidden: true,
                    dicData: [
                        {label: "停用", value: 0},
                        {label: "启用", value: 1}
                    ]
                },
                {
                    label: "检出状态",
                    prop: "checkState",
                    type: "radio",
                    overHidden: true,
                    dicData: [
                        {label: "检入", value: 1},
                        {label: "检出", value: 2},
                    ]
                },
                {
                    label: "添加到实体",
                    prop: "",
                    width: 120
                },
                {
                    label: "中文描述",
                    prop: "describeCn",
                    overHidden: true,
                },
                {
                    label: "英文描述",
                    prop: "describeEn",
                    overHidden: true,
                },
                {
                    label: "大版本规则",
                    prop: "majorRule",
                    overHidden: true,
                    width: 140
                },
                {
                    label: "分隔符",
                    prop: "separatorRule",
                    overHidden: true,
                },
                {
                    label: "小版本规则",
                    prop: "minorRule",
                    overHidden: true,
                    width: 140
                },
            ]
        }
    },
    methods: {
        validate() {
            let fn = 0;
            for (const key in this.form) {
                if (this.formData[key]) {
                    fn++;
                }
            }
            if (fn > 1) {
                return {state: true}
            }
            return {state: false, msg: "版本规则配置"}
        },

        addToList(v) {
            let obj = v[0];
            Object.assign(obj, {
                type: this.temp,
                functionName: obj.name,
                functionType: 1,
                interfaceName: "versionable"
            })
            Object.assign(this.formData, obj);
            this.selection = v;

            this.addToSettingList(obj);

            this.$refs["gdcd"].close();
        }
    },
    watch: {
        show: {
            handler(v) {
                if (v) {
                    api.getVersionCon({oid: this.formDataAll.oid, type: this.temp}).then(res => {
                        if (res.data.data) {
                            this.addToList([this.deepCopy(res.data.data)]);
                        }
                    })
                }
            },
            deep: true,
            immediate: true
        }
    }
}
</script>
<style scoped lang="scss">
.config {

  .el-col {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    flex-wrap: nowrap;
    height: 36px;
    line-height: 36px;
    font-size: 12px;

    > span {
      width: 40px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      text-align: right;
      padding-right: 10px;
      font-size: 12px;
    }

    .l4 {
      width: 100px;
    }
  }
}
</style>
